package com.ezbuy.common.request;

import io.reactivex.disposables.Disposable;

/**
 * ezbuy 2018/12/1 上午11:42
 */
public class RxRequestObserver implements RequestObserver {

    private Disposable disposable;

    public RxRequestObserver(Disposable disposable) {
        this.disposable = disposable;
    }

    @Override
    public void cancle() {
        System.out.println("请求反注册:" + disposable);
        if (isCancled()) {
            System.out.println("请求已取消,无须反注册");
        } else {
            System.out.println("请求未取消,执行反注册");
            disposable.dispose();
        }

    }

    @Override
    public void register(RequestSubject manager) {
        System.out.println("请求注册:" + disposable);
        manager.attach(this);
    }

    @Override
    public boolean isCancled() {
        return disposable.isDisposed();
    }
}
